import {reqCartList} from '@/api'

const actions = {
	async getCartList({commit}){
		const result = await reqCartList()
		if(result.code === 200){
			commit('SAVE_CART_LIST',result.data)
		}else{
			alert(result.message)
		}
	}
}

const mutations = {
	SAVE_CART_LIST(state,list){
		state.cartList = list
	}
}

const state = {
	cartList:[{cartInfoList:[]}]
}

const getters = {
	cartInfoList(state){
		return state.cartList[0] ? state.cartList[0].cartInfoList : []
	}
}

export default {
	namespaced:true,
	actions,
	mutations,
	state,
	getters
}